/*
 * ScriptPanel.java
 *
 * Created on May 20, 2008, 3:07 AM
 */

package org.opennpo.mpres.gui;

import java.awt.Color;
import java.awt.Component;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import org.opennpo.mpres.ScriptItem;
import org.opennpo.mpres.ScriptItemListener;
import org.opennpo.mpres.ScriptItemSource;

/**
 * The visual component for handling a script.
 * @author  Nate Jones
 */
public class ScriptPanel extends javax.swing.JPanel implements ScriptItemSource{
    private DefaultListModel scriptItems;
    /** Creates new form ScriptPanel */
    public ScriptPanel() {
        initComponents();
        scriptItems = new DefaultListModel();
        jList1.setModel(scriptItems);
        jList1.setCellRenderer(new ScriptItemRenderer());
    }
    
    private class ScriptItemRenderer extends JLabel implements ListCellRenderer{
        
        public ScriptItemRenderer(){
            setOpaque(true);
        }

        @Override
        public Component getListCellRendererComponent(JList list, Object value, 
                int index, boolean isSelected, boolean cellHasFocus) {
            ScriptItem item = (ScriptItem)value;
            setText(item.getTitle());
            setIcon(item.getIcon());
            if(isSelected){
                setBackground(list.getSelectionBackground());
                setForeground(list.getSelectionForeground());
            }
            else{
                setBackground(list.getBackground());
                setForeground(list.getForeground());
            }
            if(cellHasFocus){
                setBorder(BorderFactory.createRaisedBevelBorder());
            }
            else{
                setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
            }
            return this;
        }
        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();

        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.LINE_AXIS));

        jScrollPane1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(jList1);

        add(jScrollPane1);
    }// </editor-fold>//GEN-END:initComponents
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

    @Override
    public Icon getIcon() {
        return null;
    }

    @Override
    public String getTitle() {
        return "Script";
    }

    @Override
    public Component getComponent() {
        return this;
    }

    @Override
    public void addListener(ScriptItemListener l) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeListener(ScriptItemListener l) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void next() {
        
    }
    
}
